//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_COMMON_H__
#define __ELASTOS_COMMON_H__

#define __SAVE_SOFTWARE_REGS()  \
    ASM("pushl   %es;"          \
        "pushl   %ds;"          \
        "pushl   %eax;"         \
        "pushl   %ebp;"         \
        "pushl   %edi;"         \
        "pushl   %esi;"         \
        "pushl   %edx;"         \
        "pushl   %ecx;"         \
        "pushl   %ebx;")

#define __SAVE_SOFTWARE_REGS_WITHOUT_ES()   \
    ASM("pushl   %ds;"                      \
        "pushl   %eax;"                     \
        "pushl   %ebp;"                     \
        "pushl   %edi;"                     \
        "pushl   %esi;"                     \
        "pushl   %edx;"                     \
        "pushl   %ecx;"                     \
        "pushl   %ebx;")

#define __RESTORE_SOFTWARE_REGS()   \
    ASM("popl    %ebx;"             \
        "popl    %ecx;"             \
        "popl    %edx;"             \
        "popl    %esi;"             \
        "popl    %edi;"             \
        "popl    %ebp;"             \
        "popl    %eax;"             \
        "popl    %ds;"              \
        "popl    %es;")

#define __SETUP_KERNEL_REGS()   \
    ASM("cld;"                  \
        "movw   %%bx, %%ds;"    \
        "movw   %%bx, %%es;"    \
        "xor    %%ebp, %%ebp;"  \
        : :"b"(KERNEL_DATA_SELECTOR))

#endif // __ELASTOS_COMMON_H__
